package ar.edu.itba.cg.controllers;

import ar.edu.itba.cg.util.TextureUtil;

import com.jme.bounding.BoundingSphere;
import com.jme.curve.BezierCurve;
import com.jme.math.Vector3f;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.system.DisplaySystem;

public class ShootBar extends Node{
	private static final long serialVersionUID = 1L;

	private ShootController sc;
	
	public ShootBar(String name, Vector3f minPoint, Vector3f maxPoint,
			float minValue, float maxValue, DisplaySystem display){
		super(name);		
		 //create control Points
	    Vector3f[] points = new Vector3f[2];
	    points[0] = minPoint;
	    points[1] = maxPoint;
	    
	    BezierCurve curve = new BezierCurve("Curve", points);
	    curve.setRenderState(TextureUtil.getTexture(display, "verde_rojo.PNG"));
	    
	    	    
	    Vector3f min = new Vector3f( -0.1f, -0.1f, -0.1f);
	    Vector3f max = new Vector3f(0.1f, 0.1f, 0.1f);

	    TriMesh t = new Box("Control 1", min, max);
	    t.setModelBound(new BoundingSphere());
	    t.updateModelBound();

	    t.setLocalTranslation(new Vector3f(points[0]));


	    TriMesh t2 = new Box("Control 2", min, max);
	    t2.setModelBound(new BoundingSphere());
	    t2.updateModelBound();

	    t2.setLocalTranslation(new Vector3f(points[1]));

	    TriMesh box= new Sphere("Controlled Box", 20, 20, 0.5f);
	    box.setModelBound(new BoundingSphere());
	    box.updateModelBound();

	    box.setLocalTranslation(new Vector3f(points[0]));

	    sc = new ShootController(curve, box, minValue, maxValue, minPoint, maxPoint);
	    box.addController(sc);
	    sc.setRepeatType(Controller.RT_CYCLE);
	    sc.setSpeed(0.7f);

	    
	    this.attachChild(t);
	    this.attachChild(t2);
	    this.attachChild(box);
	    this.attachChild(curve);
		
	}
	
	public void stopMove(){
		sc.setSpeed(0);
	}
	
	public float getValue(){
		return sc.getValue();
	}

	public void startMove() {
		sc.setSpeed(0.7f);
		
	}
}
